<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta http-equiv="Access-Control-Allow-Origin" content="*">
		<meta http-equiv="content-security-policy">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>地址选择</title>
		<!-- build:css /css/main.css -->
		<link href="/css/mui.css" rel="stylesheet" />
		<link href="/css/iconfont.css" rel="stylesheet" />
		<link href="/css/common.css" rel="stylesheet" />
		<!-- endbuild -->
		<style>
			.mui-content {
				height: auto;
			}
			
			.product-list .mui-table-view-cell {
				border-top: 0 none;
				border-bottom: 0 none;
				margin-bottom: 0;
			}
			
			.addr-bg .mui-table-view-cell {
				border: 0 none;
			}
			
			.addr-bg.mui-table-view:before,
			.addr-bg.mui-table-view:after {
				height: 0;
			}
			
			.mui-input-row .mui-btn {
				border: 0 none;
				color: #fff;
				font-size: 14px;
				width: 80%;
				float: none;
				margin: 0 auto;
			}
			
			.mui-radio input[type='radio'],
			.mui-checkbox input[type='checkbox'] {
				width: 18px;
				height: 18px;
			}
			
			.mui-radio input[type='radio']:before,
			.mui-checkbox input[type='checkbox']:before {
				font-size: 16px;
			}
			
			.mui-radio input[type='radio']:checked:before,
			.mui-checkbox input[type='checkbox']:checked:before {
				color: #ff5200;
			}
			
			.mui-btn-blue,
			.mui-btn-primary,
			input[type=submit] {
				color: #fff;
				border: 1px solid #ff5200;
				background-color: #ff5200;
			}
		</style>

	</head>

	<body>
		<header class="mui-bar mui-bar-nav u-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">地址选择</h1>
			<span id="to_info" class="mui-icon mui-icon-bars mui-pull-right" onclick="ssdd('#fnav')"></span>
		</header>
		<nav class="mui-bar mui-bar-tab otherNav" id="fnav">
			<a class="mui-tab-item" data-id="index.html" data-url="/index.html">
				<span class="mui-icon iconfont icon-icon-home"></span>
				<span class="mui-tab-label">首页</span>
			</a>
			<a class="mui-tab-item" data-id="category.html" data-url="/category.html">
				<span class="mui-icon iconfont icon-fenlei"></span>
				<span class="mui-tab-label">分类</span>
			</a>
			<a class="mui-tab-item" data-id="search.html" data-url="/search.html">
				<span class="mui-icon iconfont icon-fenleisousuo-home"></span>
				<span class="mui-tab-label">搜索</span>
			</a>
			<a class="mui-tab-item" data-id="cart.html" data-url="/cart.html">
				<span class="mui-icon iconfont icon-gouwuche1"></span>
				<span class="mui-tab-label">购物车</span>
			</a>
			<a class="mui-tab-item" data-id="user.html" data-url="/user/user.html">
				<span class="mui-icon iconfont icon-gerenzhongxin"></span>
				<span class="mui-tab-label">我</span>
			</a>
		</nav>

		<div class="mui-content mui-scroll-wrapper" id="pullrefresh">
			<div class="mui-scroll" style="padding-bottom:50px;">
				<ul class="mui-table-view goodslist addr-bg" id="address">
				</ul>
				<div class="mui-input-row" style="margin-top:10px;border-bottom: 0;">
					<button id='addnew' class="mui-btn mui-btn-block mui-btn-primary" style="background-color: #ff5200; border-color: #ff5200;"> 添加收货地址 </button>
				</div>
			</div>
		</div>
		<!-- build:js /js/vendor.js -->
		<script src="/js/mui.min.js"></script>
		<!-- bower:js -->
		<script src="/bower_components/mockjs/dist/mock.js"></script>
		<script src="/bower_components/zepto/zepto.js"></script>
		<script src="/bower_components/Zepto-Cookie/zepto.cookie.js"></script>
		<!--  endbower -->
		<!-- endbuild -->
		<!-- build:js /js/mui.picker.js -->
		<script src="/js/mui.picker.min.js"></script>
		<script src="/js/mui.poppicker.js"></script>
		<script src="/js/city.data.js" type="text/javascript" charset="utf-8"></script>
		<!-- endbuild -->
		<!-- build:js /js/main.js -->
		<script src="/js/common.js"></script>
		<script src="/js/app.js"></script>
		<!-- endbuild -->
		<script>
			var page = 1;
			var lan = localStorage.getItem('lan');
			var tokenVal = $.fn.cookie('token');
			ifLogin(tokenVal);
			(function(mui, doc) {
				mui.init({
					statusBarBackground: '#ffffff',
					pullRefresh: {
						container: "#pullrefresh",
						down: {
							contentdown: "下拉刷新",
							contentover: "释放立即刷新",
							contentrefresh: "正在刷新...",
							callback: function() {
								getUserAddressData();
							}
						}
					}
				});
				mui('.mui-scroll-wrapper').scroll({
					deceleration: 0.0005
				});

				var getUserAddressData = function() {
					var flag = false;
					setTimeout(function() {
						$.ajax({
							url: __BATE__+'api/customerList',
							data:
							{
								token:tokenVal
							},
							type:'post',
							success:function(json) {

								if(json.ret_msg == '查询成功') {									
										var data = json.data;
										var html = '';
										for(var i=0; i<data.length; i++){
											html+=data[i];
										}
										localStorage.setItem('addrType','cart');
										$("#address").html(html);
									$('body').on("tap", '.address_edit', function(event) {
						openView('/user/address-edit.html', 'address-edit.html');
						localStorage.setItem('addrId',$(this).attr('data-id'));
					});
								} else {
									flag = true;
								}
								try {
									mui('#pullrefresh').pullRefresh().endPulldownToRefresh(true);
								} catch(e) {}
							},
							error:function(){
								serverErr();
							}
						});
					}, 50)

				};
				getUserAddressData()
				
			
				
				mui.ready(function() {
					$('body').on('click', '.single_check', function() {
						var addr_id = $(this).attr('data-id');
						$.ajax({
							url: __BATE__ + 'api/cartPre',
							type: 'post',
							async: 'false',
							data: {
								addr_id: addr_id
							},
							success: function(data) {
								if(data.ret_msg == '设置成功') {
									getUserAddressData(); 
								}
							}
						});
					});
					
					
					
					$('body').on("tap", '.address_del', function(event) {
						var addressList = $(this).parents('.address-list');
						var addr_id = $(this).attr('data-id')
						var btnArray = ['否', '是'];
						mui.confirm('确定删除地址吗？', '', btnArray, function(e) {
							if(e.index == 1) {
								$.ajax({
									url: __BATE__ + 'api/deleteAddr',
									data: {
										addr_id: addr_id
									},
									type: 'post',
									success: function(json) {
										if(json.ret_msg == '删除成功') {
											addressList.remove();
											localStorage.setItem('addrId','');
										} else {
											stip(json.ret_msg)
										}
									},
									error: function() {
										serverErr();
									}
								});
								
							}
						})
						return false;
					});
						$('body').on('tap', '#address .address-list>div', function(event){
							var thisAddrId = $(this).parent('li').attr('data-id');
								openView('/order.html'+lan, 'order.html');
						localStorage.setItem('thisAddrId',thisAddrId);
						
						
					})
					$('body').on("tap","#addnew", function() {
						openView('/user/address-add.html', 'address-add.html');
					});

				});

			}(mui, document));
		</script>
	</body>

</html>